use std::collections::{BTreeSet, HashMap};

use async_trait::async_trait;
use pingora::lb::{discovery::ServiceDiscovery, Backend};
use pingora::prelude::*;

pub struct ObService {
    pub(crate) domain: String
}

#[async_trait]
impl ServiceDiscovery for ObService {
    async fn discover(&self) -> Result<(BTreeSet<Backend>, HashMap<u64, bool>)> {
        println!("request ob for discover");

        let mut upstreams = BTreeSet::new();
        /* upstreams.insert(Backend { 
            //addr: SocketAddr::Inet(),
            addr: StdSockAddr::
            weight: 1 
        }); */

        //StdSockAddr::

        /* for addrs in iter.into_iter() {
            let addrs = addrs.to_socket_addrs()?.map(|addr| Backend {
                addr: SocketAddr::Inet(addr),
                weight: 1,
            });
            upstreams.extend(addrs);
        } */

        Ok((upstreams, HashMap::new()))
    }
}

impl ObService {

    pub fn new(domain: String) -> Box<Self> {
        Box::new(ObService {
            domain,
        })
    }

    /* pub fn new() -> IoResult<Box<Self>> {

    } */
}